*************************************************************
* Title: 2_pre_acs											*
* Authors: Peter Kuhn, Trevor Osaki, Lei Yue                *
* Purpose: To prepare ACS Data for tables	                *
* Date: September 2024                                      *
*************************************************************

version 16

clear

cd $homedir

* Access the 2019 ACS
use d3_acs2019.dta, replace

drop if region == 9
drop if age < 18 | age ==.

keep perwgt age female wbhapom educ08 region state division

* Make race dummies
gen race_white = (wbhapom == 1)
gen race_black = (wbhapom == 2)
gen race_hispanic = (wbhapom == 3)
gen race_asian = (wbhapom == 4)
gen race_islander = (wbhapom == 5)
gen race_indigenous = (wbhapom == 6)
gen race_other = (wbhapom == 7)

gen race_other_combined = (race_asian == 1 | race_hispanic == 1 | race_indigenous == 1 | race_islander == 1 | race_other == 1)

* Make dummies for education
gen education_hs = (educ08 <= 17)
gen education_some_college = (educ08 >= 18 & educ08 <= 20)
gen education_four_college = (educ08 == 21)
gen education_higher = (educ08 == 22 | educ08 == 23 | educ08 == 24)

* Make dummies for age
gen age18_24 = (age >= 18 & age <= 24)
gen age25_34 = (age >= 25 & age <= 34)
gen age35_44 = (age >= 35 & age <= 44)
gen age45_54 = (age >= 45 & age <= 54)
gen age55_64 = (age >= 55 & age <= 64)
gen age65_over = (age >= 65)

* Make dummy for male
gen male = (female == 0)


* For Table A3.1 (ACS Census regions and divisions)
gen northeast = (region == 1)
gen new_england = (division == 1)
gen mid_atlantic = (division == 2)

gen midwest = (region == 2)
gen east_north_central = (division == 3)
gen west_north_central = (division == 4)

gen south = (region == 3)
gen south_atlantic = (division == 5)
gen east_south_central = (division == 6)
gen west_south_central = (division == 7)

gen west = (region == 4)
gen mountain = (division == 8)
gen pacific = (division == 9)



* For Table A2.4 (populous states)
gen az = (state ==4)
gen ca = (state ==6)
gen fl = (state ==12)
gen ga = (state ==13)
gen il = (state ==17)
gen ind= (state ==18)
gen ma = (state ==25)
gen mi = (state ==26)
gen nj = (state ==34)
gen ny = (state ==36)
gen nc = (state ==37)
gen oh = (state ==39)
gen pa = (state ==42)
gen tn = (state ==47)
gen tx = (state ==48)
gen va = (state ==51)
gen wa = (state ==53)


* Condensed version for Table A9.1 (for comparison with weighted MTurk means)
gen race_non_white = ( race_white == 0)
gen age25_44 = (age >=25 & age <= 44)
gen age45_over = (age >= 45)
gen education_hs_some_college = (education_hs == 1 | education_some_college == 1)
gen education_college_or_above = (education_four_college == 1 | education_higher == 1)


save "d5_acs2019_analysis.dta", replace
